package com.saltedfish.tool.present;

import com.saltedfish.tool.model.ModelInfo;
import com.saltedfish.tool.net.Api;
import com.saltedfish.tool.ui.flag.FragmentFlag;
import java.io.File;
import cn.droidlover.xdroidmvp.bean.BaseModel;
import cn.droidlover.xdroidmvp.log.XLog;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
public class FlagAP extends XPresent<FragmentFlag> {




    /**
     * 上传文件
     *
     * @param filePath
     */
    public void uploadFile(String filePath) {
        File file = new File(filePath);
        RequestBody body = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody multipartBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getName(), body)
                .build();

        Api.getDyService().uploadFile(multipartBody.part(0))
                .compose(XApi.getApiTransformer())
                .compose(XApi.getScheduler())
                .compose(getV().bindToLifecycle())
                .subscribe(new ApiSubscriber<BaseModel<ModelInfo>>() {
                    @Override
                    protected void onFail(NetError error) {
                      //  getV().hideProgressDialog();
                    }
                    @Override
                    public void onNext(BaseModel<ModelInfo> result) {
                        XLog.e("wx Info", "-wx uploadFile----"+result.toString());
                       // getV().hideProgressDialog();
                        if(result.code == 200 ){
//                            User.getInstance().loginSuccess(result.result);
//                            getV().loginSuccess(result.result.userInfo);
                        }
                    }
                });

    }



}
